package top.gohigh.cameradata;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

public class SplashActivity extends AppCompatActivity {
    private static final int SHOW_TIME_MIN=500;
    private long mStartTime=0;

    Handler mHandler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case MainApplication.DATE_INIT_COMPELETED:
                    long loadingTime=System.currentTimeMillis()-mStartTime;
                    if(loadingTime<SHOW_TIME_MIN){
                        mHandler.postDelayed(toMainActivity,SHOW_TIME_MIN-loadingTime);

                    }
                    else{
                        mHandler.post(toMainActivity);
                    }
                    break;
                default:
                    break;

            }
        }
    };

    private Runnable toMainActivity=new Runnable() {
        @Override
        public void run() {
            Intent intent=new Intent(SplashActivity.this,MainActivity.class);
            SplashActivity.this.startActivity(intent);
            SplashActivity.this.finish();
            overridePendingTransition(R.anim.slide_in_right,R.anim.slide_out_left);
        }
    };

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mStartTime = System.currentTimeMillis();//记录开始时间
        MainApplication.getsInstance().initDate(mHandler);

    }
    @Override
    public void onBackPressed() {
        //super.onBackPressed();


    }
}
